import request from '@/utils/request'
import { method } from 'lodash'

export function listAdminCompetition(query) {
    return request({
        url: '/competition/admin/get',
        method: 'post',
        data: query.data,
        params: {
            current: query.current,
            size: query.size
        }

    })
}

export function listStudentCompetition(query) {
    return request({
        url: '/competition/student',
        method: 'get',
        params: {}

    })
}

//学生修改竞赛申请
export function modifiedApplication(formData){
    return request({
        url: '/competition/student/modifiedApplication',
        method: 'post',
        data: formData
    })
}
//学生上传认定材料
export function uploadFile(applicationId, file, rewardTitle, awardDate) {
    const formData = new FormData();
    formData.append('applicationId', applicationId);
    formData.append('file', file);
    formData.append('rewardTitle', rewardTitle);
    formData.append('awardDate',awardDate);
  
    return request({
      url: '/competition/student/upload',
      method: 'post',
      data: formData, // 传递 formData 作为请求体
      headers: {
        'Content-Type': 'multipart/form-data', // 设置请求头为 multipart/form-data
      },
    });
  }
  //学生选择未获奖
  export function submitWithoutAward(applicationId) {
    return request({
      url: '/competition/student/noReward'+'?applicationId='+applicationId,  
      method: 'get'
    });
  }
  //学生查看认定结果
  export function getCognizanceResult(applicationId){
    return request({
        url: '/competition/student/getCognizanceResult'+'?applicationId='+applicationId,
        method: 'get'
    })
  }

// 学生提交竞赛申请
export function postCompetitionApply(formData) {
    return request({
        url: '/competition/student',
        method: 'post',
        data: formData,
    })
}

  //学生查询已经提交认定的信息
  export function getUploadFile(applicationId) {
    return request({
      url: '/competition/student//getUploadFile'+'?applicationId='+applicationId,  
      method: 'get'
    });
  }

// 学生删除竞赛申请
export function delCompetitionApply(applicationId) {

    return request({
        url: '/competition/student/delete'+'?applicationId='+applicationId,
        method: 'post',
    })
}

// admin导出excel
export function excelCptAdmin(query) {
    return request({
        url: '/competition/admin/export',
        method: 'post',
        data: query.data,
        params: {
            current: query.current,
            size: query.size
        },
        responseType: 'blob'
    })
}

// admin审核申请（初审
export function approveCompetitionApply(bool,applicationIds) {

    return request({
        url: '/competition/admin',
        method: 'put',
        params: {
            isPass: bool
        },
        data: {
            applicationId: applicationIds
        }
    })
}

// admin审核认定（二审
export function cognizeCompetitionApply(formValue) {

    return request({
        url: '/competition/admin',
        method: 'post',
        params: formValue
    })
}
//管理员修改认证结果
export function cognizeCA_admin(formValue) {

    return request({
        url: '/competition/admin/cognizanceCheck',
        method: 'post',
        params: formValue
    })
}

// admin查看认定文件
export function getCognizanceInfo(applicationId) {
    return request({
        url: '/competition/admin/cognizanceInfo',
        method: 'get',
        params: {
            applicationId: applicationId
        }
    })
}

// admin批量下载附件
export function uploadCognizance(applicationIds) {

    return request({
        url: '/competition/admin/downloadCognizantFile',
        method: 'post',
        data: {
            cognizantIds: applicationIds
        },
        responseType: 'blob',
    })
}

// 查看认定等级
export function getCognizanceLevel(applicationId) {

    return request({
        url: '/competition/admin/getCognizanceResult',
        method: 'get',
        params: {
            applicationId: applicationId
        },
    })
}

